import { request } from '@inbiz/utils';

/**
 * 查询模型列表
 * @param appInfo app信息
 */
export async function getModelList(appInfo: any) {
  return request(
    `/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/model/publishs/${appInfo.appId}`,
    {
      params: {
        pageIndex: 1,
        pageSize: 1000,
      },
    },
  );
}

/**
 * 查询分组列表
 * @param appInfo app信息
 */
export async function getGroupList(appInfo: any) {
  return request(
    `/inbiz/api/services/engines/v${InbizConfig.API_VERSION}/pageGroup/loadGroupList`,
    {
      params: {
        siteOutId: appInfo.OutId,
        dataVersionId: appInfo.DataVersionId,
        appId: appInfo.appId,
      },
    },
  );
}

/**
 * 获取某个分组下的页面
 * @param appInfo app信息
 * @param parentId 分组id
 * @param page 搜索,分页截取信息
 */
export async function getGroupPageList(
  appInfo: any,
  parentId: any,
  page?: object,
) {
  return request(
    `/inbiz/api/services/engines/v${InbizConfig.API_VERSION}/pageGroup/loadPageList`,
    {
      params: {
        siteOutId: appInfo.OutId,
        dataVersionId: appInfo.DataVersionId,
        appId: appInfo.appId,
        parentId: parentId,
        ...page,
      },
    },
  );
}

/**
 * 保存当前菜单权限配置数据
 * @param appInfo app信息
 * @param pageOutId 页面id
 * @param pageOutIds 页面id数据
 */
export async function checkBind(
  appInfo: any,
  pageOutId: string,
  pageOutIds: any[],
) {
  return request(
    `/inbiz/api/services/engines/v${InbizConfig.API_VERSION}/page/isBind`,
    {
      params: {
        siteOutId: appInfo.OutId,
        pageOutId: pageOutId,
        pageOutIds: pageOutIds,
        dataVersionId: appInfo.DataVersionId,
      },
    },
  );
}
/**
 * 保存当前菜单权限配置数据
 * @param siteOutId 站点id
 * @param pageOutId 菜单（节点）id
 * @param data 数据
 */
export async function setConfig(appInfo: any, pageOutId: string, data: any[]) {
  return request(
    `/inbiz/api/services/engines/v${InbizConfig.API_VERSION}/menuRelation`,
    {
      method: 'POST',
      data: {
        siteOutId: appInfo.OutId,
        pageOutId,
        relationData: data,
        dataVersionId: appInfo.DataVersionId,
      },
    },
  );
}
/**
 * 获取当前菜单权限配置数据
 * @param siteOutId 站点id
 * @param pageOutId 绑定页面的id
 */
export async function getConfig(appInfo: any, pageOutId: string) {
  return request(
    `/inbiz/api/services/engines/v${InbizConfig.API_VERSION}/menuRelation/devTree`,
    {
      params: {
        siteOutId: appInfo.OutId,
        pageOutId: pageOutId,
        type: '-1',
        dataVersionId: appInfo.DataVersionId,
      },
    },
  );
}
